package com.mh.zookeeper.zkclient;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;

import static com.mh.zookeeper.PropertiesUtils.getZookeeperConnectStr;

public class GetNodeChildren {


    public static void main(String[] args) throws InterruptedException {

        ZkClient zkClient = new ZkClient(getZookeeperConnectStr());
        System.out.println("会话被创建了..");

        List<String> children = zkClient.getChildren("/lg-zkclient");
        System.out.println(children);

        zkClient.subscribeChildChanges("/lg-zkclient-get", new IZkChildListener() {
            public void handleChildChange(String parentPath, List<String> list) throws Exception {
                System.out.println(parentPath + "的子节点列表发生了变化,变化后的子节点列表为" + list);

            }
        });

        zkClient.createPersistent("/lg-zkclient-get");
        Thread.sleep(1000);

        zkClient.createPersistent("/lg-zkclient-get/c1");
        Thread.sleep(1000);

    }

}
